package game.module.battleReport.processor;

import java.util.List;

import db.proto.Protoname.Battlename;
import db.proto.Protoname.Player;
import game.common.PlayingRoleMsgProcessor;
import game.entity.PlayingRole;
import game.module.battleReport.bean.PlayerReport;
import game.module.battleReport.dao.PlayerReportCache;
import lion.common.MsgCodeAnn;
import lion.netty4.message.MyRequestMessage;
import lion.netty4.message.RequestMessageRaw;
import lion.netty4.message.RequestProtoMessage;
import lua.LuaMessageHall.C2SGetBattleReportList;
import lua.LuaMessageHall.ReportList;
import lua.LuaMessageHall.S2CGetBattleReportList;
import lua.LuaMessageLogin.S2ErrorCode;

@MsgCodeAnn(msgcode = C2SGetBattleReportList.id, accessLimit = 500)
public class GetAllReportProcessor extends PlayingRoleMsgProcessor{

	@Override
	public void process(PlayingRole playingRole, RequestMessageRaw requestMessage) throws Exception {
		// TODO Auto-generated method stub
		int playerId = playingRole.getId();
		List<PlayerReport> msg = PlayerReportCache.getInstance().getBattleReport(playerId);
		if(msg ==null) {
			S2ErrorCode respMsg = new S2ErrorCode(135);
			playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
			return;// 没有战报
		}
		S2CGetBattleReportList respMsg = new S2CGetBattleReportList();
		respMsg.battlereport = new ReportList[msg.size()];
		for(int i =0;i<msg.size();i++) {
			Battlename  players =  msg.get(i).getPlayers();
			
			respMsg.battlereport[i] = new ReportList();
			respMsg.battlereport[i].roomtype = msg.get(i).getGame_type();
			respMsg.battlereport[i].roomid = msg.get(i).getRoomid();
			int size = players.getPlayersCount();
			respMsg.battlereport[i].score = new short[size];
			respMsg.battlereport[i].playername = new String[size];
			respMsg.battlereport[i].date = (int) (msg.get(i).getDate().getTime()/1000);
			respMsg.battlereport[i].reportid = msg.get(i).getBattleperortId();
			List<Player> meplays = players.getPlayersList();
			for(int j = 0;j<size;j++) {
				
				respMsg.battlereport[i].score[j] = (short) meplays.get(j).getSocre();
				respMsg.battlereport[i].playername[j] = meplays.get(j).getName();
			}
		}
		playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));	
	}

	@Override
	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
		// TODO Auto-generated method stub
		
	}

}
